var vote= new Vue({
    el : '#Votelist',
    data:{
        userId : $("#id").val(),
        xiangmuId:$("#xiangmuId").val(),
        xiangmuleixing:'',
        yaopinmingcheng:'',
        zhuankefenzu:'',
        shenqingkeshi:'',
        xiangmu : {},
        votelist:[],
        zhuankefenzulist:[],
        shenqingkeshilist:[],
        show : false,
        total:0,
        tongyishu:0,
        butongyishu:0,

        issubmited:false,
        isallsubmited:false,

        pageIndex : 1,
        pageSize :999,
        pageCount : 0,
        recordCount : 0,
        inputPageIndexValue : "",
    },
    created : function() {
        var _this = this;

        $(".nav navbar-nav li").removeClass("active");
        $("#nav_biaojue").addClass("active");
        _this.findIsacticed();



    },
    methods : {

        toRefresh:function (){

            location.reload();
        },

        findIsacticed:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xiangmu/find_one', {
                xianmguid :_this.xiangmuId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                        _this.xiangmuId=_this.xiangmu.xiangmuid;
                        _this.xiangmuleixing=_this.xiangmu.xiangmuleixing;
                        _this.checkIsSubmited();
                        _this.checkIsAllSubmited();
                        _this.getxinguotanResultCount();
                        _this.getzhuankefenzulist();
                        _this.getshenqingkeshilist();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        checkIsSubmited:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/checkIsSubmited', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        if(ppData.resultContent=="1"){
                            _this.issubmited=true;
                        }
                        _this.findBiaojuelist();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        checkIsAllSubmited:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/checkIsAllSubmited', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        if(ppData.resultContent=="1"){
                            _this.isallsubmited=true;
                        }

                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },


        remove:function (){
            this.yaopinmingcheng="";
            this.zhuankefenzu="";
            this.shenqingkeshi="";
            this.findBiaojuelist();
        },

        findBiaojuelist:function (){
            var _this = this;
            layer.open({type:3});
            $.post("/xinguotan/findbiaojuelist",{
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                yaopinmingcheng : $.trim(_this.yaopinmingcheng),
                zhuankefenzu : _this.zhuankefenzu,
                shenqingkeshi : _this.shenqingkeshi,
                pageindex : _this.pageIndex,
                pagesize : _this.pageSize,
                rdm : Math.random()
            },function(ppData){
                layer.closeAll("loading");
                if (ppData != null){
                    if(ppData.result == "1"){
                        var data=ppData.resultContent;
                        var mmHtml = "<div class='table-head'><table class=\"table table-hover table-bordered\" style=\"overflow:hidden; margin-bottom:10px;table-layout:fixed;\" v-if=\"show\" cellspacing=\"0\" cellpadding=\"0\">\n" +
                            "   <thead >\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:50px\" >序号</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:200px\" >药品名称</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:100px\" >医保</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:100px\" >院本部药</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:100px\" >秦淮药</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:100px\" >专科分组</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:100px\" >申请科室</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:300px\" >国家平台备注信息</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:100px\" >规格1</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:100px\" >规格2</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >表决意见（同意保留请打勾）</th>\n" +
                            "    </thead></table></div><div class='table-body'><table style=\"table-layout: fixed;\"><tbody>";
                        if(data.Biaojuelist.length>0){
                            _this.show = true;
                            var PageInfo = data.PageInfo;
                            _this.pageIndex = PageInfo.pageIndex;
                            _this.recordCount = PageInfo.recordCount;
                            _this.pageCount = PageInfo.pageCount;

                            for (var i = 0; i < data.Biaojuelist.length; i++) {
                                var mmXinguotanOne = data.Biaojuelist[i];
                                var mmResult=mmXinguotanOne.result;
                                var mmId=mmXinguotanOne.id;

                                var mmpaixuhao = mmXinguotanOne.ordernumber;
                                var mmyaowumingcheng = mmXinguotanOne.yaopinmingcheng;
                                var mmyibao = mmXinguotanOne.yibao;
                                var mmyuanbenbuyao = mmXinguotanOne.yuanbenbuyao;
                                var mmqinhuaiyao = mmXinguotanOne.qinhuaiyao;
                                var mmzhuankefenzu = mmXinguotanOne.zhuankefenzu;
                                var mmshenqingkeshi = mmXinguotanOne.shenqingkeshi;
                                var mmbeizhu = mmXinguotanOne.beizhu;
                                var mmbeizhu2 = mmXinguotanOne.beizhu2;
                                var mmbeizhu3 = mmXinguotanOne.beizhu3;

                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:50px'>" + mmpaixuhao + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:200px'>" + mmyaowumingcheng + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px'>" + mmyibao + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px'>" + mmyuanbenbuyao + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px'>" + mmqinhuaiyao + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px'>" + mmzhuankefenzu + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px'>" + mmshenqingkeshi + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:300px; white-space:nowrap; -moz-text-overflow: ellipsis;text-overflow: ellipsis; overflow: hidden; text-align: left'><a title='" + mmbeizhu + "'>" + mmbeizhu + "</a></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;white-space:nowrap; -moz-text-overflow: ellipsis;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmbeizhu2 + "'>" + mmbeizhu2 + "</a></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px'>" + mmbeizhu3 + "</td>";

                                var mmBtndiv="";
                                if(_this.issubmited){
                                    if(mmResult==null||mmResult==0){
                                        mmBtndiv="<div style=\"text-align:center;\"><input disabled onclick=\"toVote('"+mmId+"')\" class='cbcss' id='checkbox_"+mmId+"' type=\"checkbox\"></div>";
                                    }
                                    if(mmResult==1){
                                        mmBtndiv="<div style=\"text-align:center;\"><input disabled checked onclick=\"toVote('"+mmId+"')\" class='cbcss' id='checkbox_"+mmId+"' type=\"checkbox\"></div>";
                                    }
                                }
                                if(!_this.issubmited) {
                                    if(mmResult==null||mmResult==0){
                                        mmBtndiv="<div style=\"text-align:center;\"><input  onclick=\"toVote('"+mmId+"')\" class='cbcss' id='checkbox_"+mmId+"' type=\"checkbox\"></div>";
                                    }
                                    if(mmResult==1){
                                        mmBtndiv="<div style=\"text-align:center;\"><input checked  onclick=\"toVote('"+mmId+"')\" class='cbcss' id='checkbox_"+mmId+"' type=\"checkbox\"></div>";
                                    }
                                }
                                mmHtml +="<td style='text-align:center;vertical-align:middle;height: 100%'>" + mmBtndiv + "</td>";

                                mmHtml += "</tr>";

                            }
                        }else {
                            _this.show = false;
                        }
                        mmHtml += "</table>";
                        $("#List").html(mmHtml);
                    }else{
                        layer.alert(ppData.message);
                    }
                }

            },"json");
        },

        getxinguotanResultCount:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xinguotanjieguo/getxinguotanResultCount', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.tongyishu=data.tongyiShu;
                        _this.butongyishu=data.butongyiShu;
                        _this.total=data.total;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },


        tosubmit:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xinguotanjieguo/submit', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        _this.issubmited=true;
                        layer.alert("提交成功");
                        //location.reload();
                        _this.findBiaojuelist();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        getzhuankefenzulist:function (){
            var _this = this;
            layer.open({type:3});

            $.post('/xinguotan/findzhuankefenzubyxiangmuid', {
                xiangmuid :_this.xiangmuId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.zhuankefenzulist = data;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        getshenqingkeshilist:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xinguotan/findshenqingkeshibyxiangmuid', {
                xiangmuid :_this.xiangmuId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.shenqingkeshilist = data;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },



        //跳到首页
        SetPageIndex : function(){
            this.pageIndex = 1;
        },
        SetPageEnd : function(){
            this.pageIndex = this.pageCount;
        },
        //上一页
        SetPageIndexPrePage : function(){
            var PrePage = ((this.pageIndex -1) <= 0) ? 1 : (this.pageIndex -1);
            this.pageIndex = PrePage;
        },
        //下一页
        SetPageIndexNextPage : function(){
            var NextPage = ((this.pageIndex +1) >= this.pageCount) ? this.pageCount : (this.pageIndex +1);
            this.pageIndex = NextPage;
        },
        //跳转界面
        JumpPage : function(){
            if(this.inputPageIndexValue <= 1){
                this.inputPageIndexValue = 1;
            }else if(this.inputPageIndexValue >= this.pageCount){
                this.inputPageIndexValue = this.pageCount;
            }
            this.pageIndex = this.inputPageIndexValue;
            this.inputPageIndexValue = '';
        },
    },
    watch :{
        //监控分页情况，刷新列表
        pageIndex : function(){

            this.findBiaojuelist();
        }
    }
})